#include "FlashCache.h"
#include "ComponentsHolder.h"
#include <sstream>
using namespace std;

FlashCache::FlashCache(long size, double readCacheSize, double writeCacheSize, CacheManagement policy): Cache(size, readCacheSize,writeCacheSize,policy)
{
	_size = (size*(GB/(FlashAlignment*KB)));
	_readSize = (readCacheSize/100.0)*_size;
	_writeSize = (writeCacheSize/100.0)*_size;
	_dirtyBitcounter = 0;



}


FlashCache::~FlashCache(void)
{

}

void FlashCache::removeLatestExtents(int count, bool isWrite)
{
	while (count < 0)
	{
		ExtentIO* head = _readList->getSize() == 0 ? _writeList->removeHead() : _readList->removeHead();
		if (head->isFromWrite() || isWrite)
			ComponentsHolder::getInstance()->getCache()->decreaseDirtyCounter();
		_extents->erase(_extents->find(getIOID(head)));
		delete head;
		count++;
	}

}
